package com.netdisk.util;

import java.math.BigDecimal;

/**
 * 容量计算
 * 
 * @author chenlong
 * 
 */
public class CapacityCount {

	public static final byte B = 0;

	public static final byte KB = 1;

	public static final byte MB = 2;

	public static final byte GB = 3;

	public static final byte TB = 4;

	private static long capacity;

	public long getCapacity() {
		return capacity;
	}

	public static long countCapacityToByte(long cap, byte unit) {

		switch (unit) {
		case 0: {
			capacity = cap; // 单位为byte
			return capacity;
		}
		case 1: {
			capacity = cap * 1024L; // 单位为kb
			return capacity;
		}
		case 2: {
			capacity = cap * 1024L * 1024L; // 单位为mb
			return capacity;
		}
		case 3: {
			capacity = cap * 1024L * 1024L * 1024L; // 单位为gb
			return capacity;
		}
		case 4: {
			capacity = cap * 1024L * 1024L * 1024L * 1024L; // 单位为tb
			return capacity;
		}
		default:
			return capacity;
		}
	}

	public static BigDecimal countCapacityToUnit(long cap, byte unit) {
		BigDecimal big = new BigDecimal(cap);
		switch (unit) {
		case 0: {
			return big; // //单位为byte
		}
		case 1: {
			big = big.divide(new BigDecimal(1024L)); // 单位为kb
			return big;
		}
		case 2: {
			big = big.divide(new BigDecimal(1024L * 1024L)); // 单位为mb
			return big;
		}
		case 3: {
			big = big.divide(new BigDecimal(1024L * 1024L * 1024L)); // 单位为gb
			return big;
		}
		case 4: {
			big = big.divide(new BigDecimal(1024L * 1024L * 1024L * 1024L)); // 单位为tb
			return big;
		}
		default:
			return big;
		}
	}
}
